<template>
	<div>



		<van-cell :title="title" is-link @click="showPopup" :value="warehouse" />

		<van-popup v-model="show" position="bottom" :style="{ height: '60%' }">
			<van-picker title="库房" show-toolbar :columns="columns" @confirm="onConfirm" @cancel="onCancel"
				@change="onChange" :default-index="0" />
		</van-popup>

	</div>
</template>

<script>
	import Cookies from 'js-cookie'
	import {
		Toast
	} from 'vant'

	import {
		get_all_warehouse

	} from "../../utils/get_all_warehouse.js"
	export default {
		name: '',
		components: {},
		props: ['Title'],
		data() {
			return {
				warehouse: '请选择库房',
				warehouse_id: '',
				show: false,
				warehouse_list: [],
				columns: [],
				access_warehouse: null,
				
				title:   this.Title? this.title=this.Title :"选择库房"

			}
		},
		methods: {
			send_to_parent() {



				this.$emit('listenToChangeWarehouseEvent', {
					'warehouse_id': this.warehouse_id
				})

			},
			showPopup() {
				this.show = true;
			},

			onConfirm(value, index) {
				Toast(`当前值：${value}, 当前索引：${index}`);
				this.warehouse = value
				this.warehouse_id = this.warehouse_list[index]['id']
				this.show = false
				this.send_to_parent()

			},
			onChange(picker, value, index) {
				Toast(`当前值：${value}, 当前索引：${index}`);
				this.warehouse = value
				this.warehouse_id = this.warehouse_list[index]['id']
				// console.log(this.warehouse_id)
				this.send_to_parent()
			},
			onCancel() {
				// Toast('取消');
				this.show = false
			},


			//获取指定库房的所有货位 select_warehouse_location


		},
		computed: {},
		watch: {
			Title: function(val, oldval){
				// console.log(val)
				// console.log(oldval)
				this.title = val
				console.log(this.title)
			}
		},
		created() {},
		mounted() {


			let duty = Cookies.get('duty')

			if (duty.indexOf('SUPER') != -1) {

				this.access_warehouse = 'all'

				// console.log(duty.indexOf('SUPER'))

			} else if (duty.indexOf('更乐项目仓库') != -1) {

				this.access_warehouse = '168'

				// console.log(duty.indexOf(duty.indexOf('更乐项目仓库')))
				// console.log('11111111111111')

			}

			get_all_warehouse((res)=>{
				// console.log(res)
				this.warehouse_list = res
				for (let i = 0; i < this.warehouse_list.length; i++) {
					this.columns.push(this.warehouse_list[i]['warehouse_name'])
				}
			})


		},
	}
</script>

<style scoped lang="less">
	.cell_header_title {
		background-color: #F0F0F0;
		font-weight: 800;
	}
</style>
